package com.cycle.community.util;

import com.cycle.community.entity.User;
import org.springframework.stereotype.Component;

/**
 * @author lenovo
 * @create 2022/8/13 16:24
 */

/**
 * 持有用户信息，用来代替session对象
 */
@Component
public class HostHolder {
    //    每个线程得到的不一样
    private ThreadLocal<User> users = new ThreadLocal<>();

    public void setUser(User user) {
        users.set(user);
    }

    public User getUser() {
        return users.get();
    }

    public void clear(){
        users.remove();
    }

}
